Shader "dissolve"
{
    Properties
    {
        _Color ("Color", Color) = (0,1,1,1)
        _MainTex ("Albedo(RGB)", 2D) = "white" {}
        _noiseMap ("noiseMap", 2D) = "white" {}
        _dissolveColor1 ("混合颜色1", Color) = (0,0,1,1)
        _dissolveColor2 ("混合颜色2", Color) = (0,1,1,1)
        _lineWidth("线宽", Float) = 0.5
        _dissolveThreshold("阈值", Float) = 0.1

    }
    // 片元着色器
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
        sampler2D _noiseMap;
     
        float _lineWidth;
        float _dissolveThreshold;


        struct Input
        {
            float2 uv_MainTex;
        };

        fixed4 _Color;
        fixed4 _dissolveColor1;
        fixed4 _dissolveColor2;
        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

      void surf (Input IN, inout SurfaceOutputStandard o)
        {
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            fixed4 noise = tex2D (_noiseMap, IN.uv_MainTex);

            // 根据溶解阈值进行溶解
            if (noise.r < _dissolveThreshold) {
                discard;
            }

            // 根据线宽和溶解阈值调整溶解程度
            float dissolveAmount = 1.0 - smoothstep(0.0, _lineWidth, noise.r - _dissolveThreshold);

            // 混合两种溶解颜色
            fixed4 dissolveColor = lerp(_dissolveColor1, _dissolveColor2, dissolveAmount);

            // 应用溶解颜色到表面输出的 Albedo
            o.Albedo = lerp(c.rgb, dissolveColor.rgb, dissolveAmount);

            // 设置透明度
            o.Alpha = c.a;
        }

        ENDCG
    }
    FallBack "Diffuse"
}
